package com.imooc.scala.course04

import org.apache.avro.ipc.specific.Person

object ConstrutorApp {
  def main(args: Array[String]): Unit = {

//    val  person = new Person("zhangshan",39)
//    println(person.name + ":" + person.age + ":" + person.school)
//
//    val  person2 = new Person("PK",19,gender = "M")
//    println(person2.name + ":" + person2.age + ":" + person2.school+ ":" + person2.gender)


    val student = new Student("PK",18,"Math")
    println(student.name + ":" + student.age + ":" + student.major)

    println(student.toString)


  }
}


// 主构造器
// 如果将val去掉，将无法访问name?
class Person(val name:String,val age:Int){
  println("person Constructor enter")

  val school = "ustc"
  var gender:String = _

  //附属构造器
  def this(name: String,age:Int,gender:String){
    this(name,age)//附属构造器的第一行代码 必须要调用柱构造器或者其他附属构造器
    this.gender = gender
  }
  println("Person Constructor leave...")

}

class Student(name: String,age:Int, var major:String) extends Person(name,age){
  println("Person student enter,,,")

  override val school: String = "TIAN JING"
  override def toString: String = "Person this  is overwrite   " + school

  println("Person Student leave ...")
}